<?php

namespace app\dao;

use app\model\ClubModel;
use think\facade\Log;

class ClubDao
{
    // 创建社团
    public static function createClub($data)
    {
        try {
            return ClubModel::create($data);
        } catch (\Exception $e) {
            Log::error("创建社团失败: " . $e->getMessage());
            return null;
        }
    }

    // 获取所有社团
    public static function getAllClubs()
    {
        try {
            return ClubModel::select();
        } catch (\Exception $e) {
            Log::error("获取所有社团失败: " . $e->getMessage());
            return [];
        }
    }

    // 获取社团详情
    public static function getClubById($id)
    {
        try {
            return ClubModel::find($id);
        } catch (\Exception $e) {
            Log::error("获取社团详情失败: " . $e->getMessage());
            return null;
        }
    }

    // 更新社团
    public static function updateClub($id, array $data)
    {
        try {
            return ClubModel::where('id', $id)->update($data);
        } catch (\Exception $e) {
            Log::error("更新社团失败: " . $e->getMessage());
            return false;
        }
    }

    // 删除社团
    public static function deleteClub($id)
    {
        try {
            return ClubModel::where('id', $id)->delete();
        } catch (\Exception $e) {
            Log::error("删除社团失败: " . $e->getMessage());
            return false;
        }
    }
}
